package 牛客剑指专题二刷.二叉树;

/**
 * author:JiangSong
 * Date:2023/7/3
 **/

/**
 * 二叉树的深度
 法1：后序遍历,左右根；
 */

public class JZ55 {
    class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;

        }
    }



    public int TreeDepth(TreeNode root) {
        if(root == null)return 0;
        //计算左右子树高，在加上当前点
        int left = TreeDepth(root.left);
        int right = TreeDepth(root.right);
        return Math.max(left, right) + 1;
    }
}
